<?php include "inc/conn.php";?><?php include "inc/pubs.php";?>
<?php include "inc/safe.php";?><?php include "inc/sqls.php";?>
<?php
$th = $_COOKIE['name'];
$dn = $_COOKIE['pass'];
//判断是否记忆登陆
If($dn == md5($th.$ao)){
}else{
webalert("请重新登陆(B1)!","login.php?tt=".$tts);
}
if(file_exists($ld)){
$xi = Trim(fi($ld, 2));
if($xi <> md5($th)){
webalert("无权操作(Li2)!","index.php?tt=".$tts);
}
}
$db=ConnectMysqli::getIntance($conn);
$ah = Trim($_GET['na']);
$pici = Trim($_GET['pi']);
if(stristr("-csv-txt-","-{$ah}-")){
if($ah=="txt"){$geva="\t";}else{$geva=",";}
$br = "{$pici}.{$tts}.zip";
$zip = new ZipArchive;
$res = $zip->open($br, ZipArchive::CREATE);
if($res === TRUE) {
$xx="SELECT DISTINCT `{$tv}` FROM `{$no}`";
$xx.=" WHERE `{$rf}` = '{$pici}' ";
$xx.=" AND `isyue` in (1,2) ";
$eq=$db->query($xx);
$ia = 0;
while($we = mysqli_fetch_array($eq)){
$ia++; $ch=$we[$tv];
$filename = "{$ch}.{$tts}.{$ah}";
$ic = ck($filename);
$wf = " WHERE `{$rf}` = '{$pici}' AND `{$tv}` = '{$ch}' ";
$wf.= " AND `isyue` in (1,2) ";
$fn="SELECT *  FROM `{$no}` {$wf}";
$pe=$db->getAll($fn);
$ii=0; $ok = "";
foreach ($pe as $key => $rowy) {
$ii ++;
if($ii<2){
foreach ($rowy as $kay => $raw) {
$ok .= $kay.$geva;
}
$ok .= "\r\n";
}
foreach ($rowy as $kay => $raw) {
$ok .= $raw.$geva;
}
$ok .= "\r\n";
}
if($ii>0){
$zip->addFromString($ic, $ok);
}else{
$zip->addFromString("空白的@".$ic, "$ic 无内容");
}
}
$filename = "说明.txt";
$ic = ck($filename);
if($ah=="txt"){
$to = "txt打开方式：右键记事本打开后复制内容到空白Excel表查看。\r\n";
$to.= "建议先空白表全选所有单元格先将格式设置为文本。\r\n";
}else{
$to = "csv打开方式：双击记事本Excel可打开；遇数字带e+或#号,先拉长该列宽度。\r\n";
}
$to .= "\r\n导出数据用于excel排版后打印，供现场使用，凭身份证领取并现场付费；\r\n";
$to .= "同时对应行签字以防止重复领取。\r\n\r\n";
if($ia<1){
$to .= "该批次{$pici}不存在!";
}
$to .= "下载时间:{$tts}!";
$zip->addFromString($ic, " $to ");
$zip->close();
}
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($br)); //文件名
header("Content-Type: application/zip"); //zip格式的
header("Content-Transfer-Encoding: binary"); //告诉浏览器，这是二进制文件
header('Content-Length: '. filesize($br)); //告诉浏览器，文件大小
@readfile($br);
if (!unlink($br))  {
}else{
}
exit();
}
?><!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
<meta name="apple-esle-web-app-capable" content="yes" />
<title>批次下载 - <?php echo $title; ?></title>
<meta name="author" content="yujianyue, admin@ewuyi.net">
<meta name="copyright" content="www.12391.net">
<link href="inc/css/style.css<?php echo $dp; ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="inc/js/js.js<?php echo $dp; ?>"></script>
</head>
<body onLoad="inst();">
<div class="html">
<div class="divs" id="divs">
<div id="head" class="head" >
<div class="bs">批次下载(推荐微信电脑客户端操作)</div>
<div class="back" id="le">
<ul id="menu" class="center">
<li class="menu"><a href="#" class="btn">更多</a>
<dl class="list" id="list">
<li><a href="index.php?t=<?php echo $tts; ?>" class="d">我的预约</a></li>
<li><a href="bang.php?t=<?php echo $tts; ?>" class="d">我要预约</a></li>
<?php
if(file_exists($ld)){
$xi = Trim(fi($ld, 2));
if($xi == md5($th)){
?>
<li><a href="list.php?t=<?php echo $tts; ?>" class="d">所有预约</a></li>
<li><a href="down.php?t=<?php echo $tts; ?>" class="d">导出预约</a></li>
<?php
}
}
?>
</dl></li>
</ul>
</div>
</div>
<div class="main" id="main">
<?php
echo "<h1>&nbsp;</h1>\r\n";
echo "<div style=\"margin:0 auto;overflow-x:auto;width:98%;max-width:1188px;\">";
echo "\r\n<!--startprint-->\r\n<h1></h1>\r\n";
echo "<table cellspacing=\"0\" class=\"table\"> \r\n";
echo "\r\n<thead><tr class=\"tt\"><td>预约批次</td><td>网点信息</td><td>计划数量</td>";
echo "<td>已被领取</td><td>下载信息</td></tr>\r\n</thead>\r\n<tbody>";
$ii=0;
$sql="SELECT DISTINCT `{$rf}` FROM `{$no}`";
$sql.=" WHERE `isyue` in (1,0,2) ";
$pass=$db->query($sql);
$ia = 0;
while($sw = mysqli_fetch_array($pass)){
$rea = $sw[$rf]; $wy = $sw[$rf]; $ia++;
echo "<tr><td data-label=\"预约批次：\">$rea</td>\r\n";
$alink = "<a href='shop.php?pi={$rea}'>查看网点</a>";
echo "<td data-label=\"查看网点：\">$alink</td>\r\n";
//查询网点批次剩余数量
$qu="SELECT COUNT(*) FROM `{$no}` WHERE `{$rf}` = '{$rea}'";
$wx=$db->getRow($qu);
$ho=$wx['COUNT(*)'];
if($ho<1){
echo "<td data-label=\"规划数量：\"><strong>-</strong></td>\r\n";
}else{
echo "<td data-label=\"规划数量：\">$ho</td>\r\n";
}
//查询网点批次剩余数量
$sqls="SELECT COUNT(*) FROM `{$no}` WHERE `{$rf}` = '{$rea}'";
$sqls.=" AND `isyue` in (1,2)";
$list=$db->getRow($sqls);
$recs=$list['COUNT(*)'];
if($recs<1){
echo "<td data-label=\"已约数量：\"><strong>-</strong></td>\r\n";
echo "<td data-label=\"不可下载：\"><strong>-</strong></td>\r\n";
}else{
echo "<td data-label=\"已约数量：\">$recs</td>\r\n";
$blink = "<a href='?pi={$rea}&na=csv'>csv</a>";
$ey = "<a href='?pi={$rea}&na=txt'>txt</a>";
$ap = "<a href='?pi={$rea}&na=xls'>xls</a>";
echo "<td  data-label=\"预约下载：\">$blink $ey</td>\r\n";
}
echo "</tr>\r\n";
}
echo "</tbody></table>\r\n";
if($ia<1){
echo "<!-- $sql -->\r\n";
}
?>
</div>
<div class="so_bus" id="tishi">
<!--你的其他说明在这里添加：开始-->
推荐微信电脑客户端操作。
<!--你的其他说明在这里添加：结束-->
</div>
</div>
<?php include "inc/foot.php";?>
</div>
</div>
</body>
</html>